package com.example.leetcode;

import java.util.ArrayList;
import java.util.List;

public class HW12 {
    public static void main(String[] args) {
        String s="fAdDAkBbBq";
        int num =4;
       char[] chars = s.toCharArray();
        List<Character> characterList = new ArrayList<>();
        for (char c:chars){
            characterList.add(c);
        }
        characterList.sort(Character::compareTo);
        if (num>characterList.size()){
            System.out.println(s.indexOf(characterList.get(characterList.size()-1)));
        }else {
            System.out.println(s.indexOf(characterList.get(num-1)));
        }

     /*   char[] chars = s.toCharArray();
        ArrayList<Character> list = new ArrayList<>();
        for (char aChar : chars) {
            list.add(aChar);
        }

        list.sort(Character::compareTo);
        char c = num >= list.size() ? list.get(list.size() - 1) : list.get(num - 1);
        System.out.println(s.indexOf(c));*/
    }

}

